package threadcoreknowledge.createthread.threadobjectclasscommommethods;

import java.util.concurrent.TimeUnit;

/**
 * 先join再mainThread.getState()
 *
 * 子线程join期间，主线程的状态是waiting
 *
 * 通过debugger看线程join前后状态的对比
 */
public class JoinThreadState {
    public static void main(String[] args) throws InterruptedException {
        Thread mainThread = Thread.currentThread();
        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    TimeUnit.SECONDS.sleep(3);
                    System.out.println(mainThread.getState());
                    System.out.println("Thread-0运行结束");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        });

        thread1.start();
        System.out.println("等待子线程运行完毕");
        thread1.join();
        System.out.println("子线程已经运行结束");
    }

}
